//
//  movieHandel.m
//  iNews
//
//  Created by lanou3g on 14-12-5.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "movieHandel.h"
#import "NetRequest.h"
#import "movieDataModel.h"
#import "videoDteilModel.h"
#import "Reachability.h"
static movieHandel *movieData = nil;
@implementation movieHandel

- (void)dealloc
{
  
    [_hostDetailArray release];
    [_hostArray release];
    [_entrainArray release];
    [_goodArray release];
    [_funnyArray release];

  
    
    [super dealloc];
}

+(movieHandel *)movieshareData{

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        movieData = [[movieHandel alloc] init];
        
     
    });

    return movieData;
    
}


//-(void)setNetnot{
//
//   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
//    
//    hostReach = [[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];
//    [hostReach startNotifier];  //开始监听，会启动一个run loop
//
//}
//
//
////网络链接改变时会调用的方法
//-(void)reachabilityChanged:(NSNotification *)note
//{
//    Reachability *currReach = [note object];
//    NSParameterAssert([currReach isKindOfClass:[Reachability class]]);
//    
//    //对连接改变做出响应处理动作
//    NetworkStatus status = [currReach currentReachabilityStatus];
//    //如果没有连接到网络就弹出提醒实况
//    if(status == NotReachable)
//    {
//        NSLog(@"网络异常");
//        _netYes = NO;
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络异常" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
//        [alert show];
//        [alert dismissWithClickedButtonIndex:0 animated:YES];
//        [alert release];
//    }
//    else
//    {
//        NSLog(@"网络正常");
//        _netYes = YES;
//    }
//}
//



//请求热点首页数据
-(void)requestMovieDataWithString:(NSString *)Dastring key:(NSString *)keystring{
    
    __block movieHandel * blockself = self;
    //__unsafe_unretained movieHandel *  blockself = self;
    [NetRequest netReuestWithUrlString:[Dastring stringByAppendingString:[NSString stringWithFormat:@"%ld-10.html",(long)self.sdr]] block:^(NSData *data) {

        NSDictionary *Datadict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil];
        NSMutableArray *temparray;
        if (self.sdr == 0) {
            temparray = [NSMutableArray array];
        }else{
        
            temparray = [NSMutableArray arrayWithArray:blockself.hostArray];
            
        }
        
        for (NSDictionary *dict in Datadict[keystring])
        {
           movieDataModel*m = [[[movieDataModel alloc] init] autorelease];
            
            [m setValuesForKeysWithDictionary:dict];
    
            [temparray addObject:m];
            //NSLog(@"%@",m.vid);
        }
        

        blockself.hostArray = [NSMutableArray arrayWithArray:temparray];

        
    }];
    
}

//请求娱乐首页数据
-(void)requestentrainDataWithString:(NSString *)Dastring key:(NSString *)keystring{

    __block movieHandel * blockself = self;
    //__unsafe_unretained movieHandel *  blockself = self;
    [NetRequest netReuestWithUrlString:[Dastring stringByAppendingString:[NSString stringWithFormat:@"%ld-10.html",(long)self.sdr1]] block:^(NSData *data) {
        
        NSDictionary *Datadict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil];
        NSMutableArray *temparray;
        
        if (self.sdr1 == 0) {
            temparray = [NSMutableArray array];
        }else{
            
            temparray = [NSMutableArray arrayWithArray:blockself.entrainArray];
            
        }
        
        for (NSDictionary *dict in Datadict[keystring])
        {
            movieDataModel*m = [[[movieDataModel alloc] init] autorelease];
            
            [m setValuesForKeysWithDictionary:dict];
            
            [temparray addObject:m];
            //NSLog(@"%@",m.vid);
        }
        
        blockself.entrainArray = [NSMutableArray arrayWithArray:temparray];
        
    }];


}



//请求搞笑首页数据
-(void)requestfunnyDataWithString:(NSString *)Dastring key:(NSString *)keystring{
    __block movieHandel * blockself = self;
    //__unsafe_unretained movieHandel *  blockself = self;
    [NetRequest netReuestWithUrlString:[Dastring stringByAppendingString:[NSString stringWithFormat:@"%ld-10.html",(long)self.sdr2]] block:^(NSData *data) {
        
        NSDictionary *Datadict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil];
        NSMutableArray *temparray;
        
        if (self.sdr2 == 0) {
            temparray = [NSMutableArray array];
        }else{
            
            temparray = [NSMutableArray arrayWithArray:blockself.funnyArray];
            
        }
        for (NSDictionary *dict in Datadict[keystring])
        {
            movieDataModel*m = [[[movieDataModel alloc] init] autorelease];
            
            [m setValuesForKeysWithDictionary:dict];
            
            [temparray addObject:m];
            //NSLog(@"%@",m.vid);
        }
        
       
        blockself.funnyArray = [NSMutableArray arrayWithArray:temparray];
        
    }];



}
//请求精品首页数据
-(void)requestgoodDataWithString:(NSString *)Dastring key:(NSString *)keystring{

    __block movieHandel * blockself = self;
    //__unsafe_unretained movieHandel *  blockself = self;
    [NetRequest netReuestWithUrlString:[Dastring stringByAppendingString:[NSString stringWithFormat:@"%ld-10.html",(long)self.sdr3]] block:^(NSData *data) {
        
        NSDictionary *Datadict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil];
   
        NSMutableArray *temparray;
        if (self.sdr3 == 0) {
            temparray = [NSMutableArray array];
        }else{
            
            temparray = [NSMutableArray arrayWithArray:blockself.goodArray];
            
        }
        
        for (NSDictionary *dict in Datadict[keystring])
        {
            movieDataModel*m = [[[movieDataModel alloc] init] autorelease];
            
            [m setValuesForKeysWithDictionary:dict];
            
            [temparray addObject:m];

        }
        
        blockself.goodArray = [NSMutableArray arrayWithArray:temparray];
        
    }];



}


//请求视频详情数据
-(void)requestMovieDetaildata:(NSString *)detailString{
    
     __block movieHandel * blockself = self;
    
   
        [NetRequest netReuestWithUrlString:[kmoviewdtaidataString stringByAppendingString:[NSString stringWithFormat:@"%@.html",self.str]] block:^(NSData *data) {
            
            
            NSDictionary *Datadict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil];
            // NSLog(@"%@",Datadict);
            
            NSMutableArray *temparray = [NSMutableArray array];
            for (NSDictionary *dict in Datadict[detailString])
            {
                videoDteilModel *vm = [[[videoDteilModel alloc] init] autorelease];
                
                [vm setValuesForKeysWithDictionary:dict];
                
                [temparray addObject:vm];
                
                
            }
            
            blockself.hostDetailArray = [NSMutableArray arrayWithArray:temparray];
            
        }];
        
  
    
    
}





@end
